package com.qy139.orderr.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qy139.entity.Orderr;
import com.qy139.entity.RoomQueryForm;
import com.qy139.orderr.service.IOrderrService;
import com.qy139.orderr.util.RandomUtil;
import com.qy139.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author huyueheng
 * @since 2021-12-15
 */
@RestController
@RequestMapping("/orderr")
public class OrderrController {
    @Resource
    IOrderrService iOrderrService;

    @GetMapping("/find")
    public Result findAll(Page page, RoomQueryForm roomQueryForm) {
        IPage page1 = iOrderrService.findAll(page,roomQueryForm);
        return new Result(page1);
    }
    @GetMapping("/findincome")
    public  Result findincome(RoomQueryForm roomQueryForm){

        return new Result(iOrderrService.findIncome(roomQueryForm));
    }
    @PostMapping("insertincome")
    public Result insertincome(@RequestBody RoomQueryForm queryForm){
        return new Result(iOrderrService.insertincome(queryForm));
    }
    @PutMapping("/updaterecord")
    public Result updateRecord(@RequestBody Orderr orderr){
        orderr.setDeleted(1);
        return  new Result( iOrderrService.updateById(orderr));
    }
    @PostMapping("/insert")
    public Result insert(@RequestBody Orderr orderr){
        System.out.println(orderr);
        Date date = new Date();
        orderr.setCreatetime(date);
        orderr.setDeleted(0);
        Calendar cal = new GregorianCalendar();
        String a=  RandomUtil.toDateString(cal);
        orderr.setIdcode(a);
        return new Result(iOrderrService.save(orderr));
    }
    @PutMapping("/updateorder")
    public Result updateorderr(@RequestBody Orderr orderr){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("idcode",orderr.getIdcode());
        return  new Result( iOrderrService.update(orderr,queryWrapper));
    }
}

